package olympicgameslogic;

import java.io.Serializable;



/**
 *
 * @author Fábio
 */
public class Modality implements Serializable, Comparable<Modality> {

   private String name;
   private LinkedList<Discipline> disciplines = new LinkedList();

   public Modality() {
   }
   

   public Modality(String nome) {
      this.name = nome;

   }

   /**
    * @return the name
    */
   public String getName() {
      return name;
   }

   /**
    * @param name the name to set
    */
   public void setName(String name) {
      this.name = name;
   }

   /**
    * @return the disciplines
    */
   public LinkedList<Discipline> getDisciplines() {
      return disciplines;
   }

   /**
    * @param disciplines the disciplines to set
    */
   public void setDisciplines(LinkedList<Discipline> disciplines) {
      this.disciplines = disciplines;
   }
   
   
   public void addDiscipline(Discipline discipline){
      disciplines.add(discipline);
   }

   @Override
   public int compareTo(Modality m) {
      return name.compareToIgnoreCase(m.getName());
      
   }

   @Override
   public String toString() {
      return this.name;
     // return this.name + "\n" + this.disciplines;
   }

   public Discipline getDiscipline(String discipline, Discipline.DISCIPLINETYPE type) {
      
      
      for (Discipline d : disciplines) {
	 if (d.getName().trim().equalsIgnoreCase(discipline.trim()) && d.getType().equals(type))
	    return d;
     }
     return null;
     
   }
   
   public Discipline getDiscipline(String discipline) {
      
      
      for (Discipline d : disciplines) {
	 if (d.getName().trim().equalsIgnoreCase(discipline.trim()) )
	    return d;
     }
     return null;
     
   }
   
   
   
   
   
   
   
   
}
